#temporary console interface to gateway, no use by third persons supported
#@author: Paweł Pawłowski <abdul-pablo@tlen.pl>

from wsn_comm import WSNSerialComm

def recHumidity(humidity):
    print 'Humidity: ' + str(humidity)

def recValve(valve):
    print 'Valve: ' + str(valve)

def recWater(water):
    print 'Water: ' + str(water)

def recAlert(alert):
    print 'Alert: ' + str(alert)

def displayMsg(msg):
    print 'Message: ' + str(msg)

w = WSNSerialComm(recHumidity,recWater,recValve,displayMsg,recAlert)

command = None
while(command != 'e'):
    print "E: exit, V: control valve, D: data request"
    command = raw_input('Enter the command: ').lower()[0]
    if command.lower() == 'v':
        valve = int(raw_input('Give required valve throttle value: '))
        w.sendValveControlMsg(valve)

    if command.lower() == 'd':
        rn = raw_input('Renew: ').lower()

        requested_data = ('humidity','valve')

        renew = []
        if 'h' in rn:
            renew.append('humidity')
        if 'w' in rn:
            renew.append('water')
        if 'v' in rn:
            renew.appen('valve')


        w.sendDataRequestMsg(requested_data, renew)